package com.woniuxy.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.entity.Cart;
import com.woniuxy.entity.OrderItem;
import com.woniuxy.mapper.CartMapper;
import com.woniuxy.mapper.OrderItemMapper;
import com.woniuxy.service.CartService;
import com.woniuxy.service.OrderItemService;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.entity.Dish;
import com.woniuxy.entity.Order;
import com.woniuxy.entity.OrderItem;
import com.woniuxy.mapper.DishMapper;
import com.woniuxy.mapper.OrderItemMapper;
import com.woniuxy.mapper.OrderMapper;
import com.woniuxy.service.OrderItemService;
import com.woniuxy.service.OrderService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Slf4j
@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements OrderItemService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private OrderItemMapper orderItemMapper;
    @Autowired
    private DishMapper dishMapper;;


/**
* @description: 根据订单ID获取订单详情
 * @param id:
 * @return: com.woniuxy.entity.OrderItem
 * @date: 2021/8/16 10:25
 * @author: 魏炳豪
 */
    @Override
    public List<OrderItem> getByOrderId(int id) {
        List<OrderItem> orderItems = orderItemMapper.getByOrderId(id);
        orderItems.forEach(p->{
            Dish dish=dishMapper.selectById(p.getDishId());
            p.setDish(dish);
        });
    return orderItems;

    }

    public void adds(OrderItem orderItem){
        orderItemMapper.adds(orderItem);
    };
}

